#!/usr/bin/env bash

date "+%Y-%m-%d %H:%M:%S"
date "+%Y-%m-%d %T"
date "+%Y-%m-%d %X"

format="+%Y-%m-%d"
arr=("3 day" "-3 day" "next day" "next week" "tomorrow" "1 day ago")
for k in ${!arr[*]}
do
    v=${arr[$k]}
    echo "$v : "$(date -d "$v" "$format")
done

echo "=============================="

dt="2010-01-01 12:59:59"
sec=$(date -d "$dt" "+%s")
convert=$(date -d "1970-01-01 UTC $sec second" "+%Y-%m-%d %H:%M:%S")
echo "$dt -> $sec -> $convert"

dt="20100101"
sec=$(date -d "$dt" "+%s")
convert=$(date -d "1970-01-01 UTC $sec second" "+%Y%m%d")
echo "$dt -> $sec -> $convert"

dt="2010-01-01 00:00:00"
sec=$(date -d "$dt" "+%s")
convert=$(date -d "1970-01-01 UTC $sec second" "+%Y%m%d")
echo "$dt -> $sec -> $convert"

echo "=============================="

begin_date="20110101"
end_date="20110201"
curr_date=$begin_date
while [[ $curr_date -le $end_date ]]
do
    echo $curr_date
    curr_date=$(date -d "$curr_date 1 day" "+%Y%m%d")
done

echo "=============================="

now=$SECONDS
echo $now
sleep 3
echo $SECONDS

echo "=============================="
